# Contributor: Clayton Craft <clayton@craftyguy.net>
# Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=gnss-share
pkgver=0.7.2
pkgrel=4
pkgdesc="GNSS location provider, supporting multiple concurrent clients"
url="https://gitlab.com/postmarketOS/gnss-share"
arch="all"
license="GPL-3.0-or-later"
makedepends="go scdoc"
subpackages="
	$pkgname-doc
	$pkgname-geoclue::noarch
	$pkgname-openrc
	"
source="
	https://gitlab.com/postmarketOS/gnss-share/-/archive/$pkgver/gnss-share-$pkgver.tar.gz
	geoclue.conf
	"

export CGO_ENABLED=0
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -v -o gnss-share ./cmd/gnss-share
	scdoc < doc/gnss-share.1.scd > gnss-share.1
	scdoc < doc/gnss-share.conf.5.scd > gnss-share.conf.5
}

check() {
	go test ./...
}

package() {
	install -Dm755 "gnss-share" \
		"$pkgdir/usr/bin/gnss-share"

	install -Dm644 "gnss-share.conf" \
		"$pkgdir/etc/gnss-share.conf"

	install -Dm755 "openrc/gnss-share.initd" \
		"$pkgdir/etc/init.d/gnss-share"
	install -Dm755 "openrc/gnss-share.confd" \
		"$pkgdir/etc/conf.d/gnss-share"
	install -Dm644 "$srcdir"/geoclue.conf \
		"$pkgdir"/etc/geoclue/conf.d/gnss-share.conf

	install -Dm644 gnss-share.1 -t "$pkgdir"/usr/share/man/man1/
	install -Dm644 gnss-share.conf.5 -t "$pkgdir"/usr/share/man/man5/
}

geoclue() {
	install_if="$pkgname=$pkgver-r$pkgrel geoclue"

	amove etc/geoclue/conf.d/gnss-share.conf
}

sha512sums="
bfecc725ea09e1fb0bbfb917478447235aa7392f54cace9686d037478f1c164388054b4f2c742ec4948871cf68871956b1ef0f99a2ca621a9911efd5637c919a  gnss-share-0.7.2.tar.gz
f1d1c391d7104dd079ee6c7c08b99f6a84749b59eb66f3ceb1994d36198840e81f011b573af455eff1231ddbaf0c786c77785f799355d6d82005317633bca1ed  geoclue.conf
"
